package cn.qianyan.controllers;

import cn.qianyan.beans.Device;
import cn.qianyan.service.HardWareService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author:
 * @createDate:
 * @description:
 */
@Controller
@ResponseBody
@RequestMapping("hardWare")
public class HardWareController {

    @Autowired
    private HardWareService hardWareService;

    @RequestMapping("updateDev")
    public int updateDev(@RequestBody Device device){//硬件设备调用此接口修改设备信息
//        Device device = new Device();
//        device.setDid(did);
//        device.setDstate(dstate);
//        device.setDtemperature(dtemperature);dtemperature

        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//设置日期格式
        device.setDbreakTime(df.format(new Date()));// new Date()为获取当前系统时间
        int i = hardWareService.updateDev(device);
        if (i==0){
            return 0;
        }
        return 10026;
    }

}
